function getUserInfo(url,user_id){
//	获取用户基本信息
	$.ajax({
		"type":"get",
		"url":url,
		"data":{
			"user_id":user_id
		},
		success:function(data){
			console.log("userinfo="+data);
			var userinfo = JSON.parse(data).userinfo;
			appendUserInfo(userinfo);
		
		},
		error:function(){
			console.log("error");
		}
	})
}
function appendUserInfo(userinfo){
	var username = "<label class='well-sm lifont'>"+userinfo.username+"</label>";
	$(username).appendTo("#username");
	var phonenumb = "<label class='well-sm lifont'>"+userinfo.phonenumb+"</label>";
	$(phonenumb).appendTo("#phonenumb");
	var email = "<label class='well-sm lifont'>"+userinfo.email+"</label>";
	$(email).appendTo("#email");
	var sex = " <label class='well-sm lifont' >"+userinfo.sex+"</label>";
	$(sex).appendTo("#sex");
	var birth = " <label class='well-sm lifont' >"+userinfo.birth.replace(/_/g," / ")+"</label>";
	$(birth).appendTo("#birth");
	var idcardnumb = " <label class='well-sm lifont' >"+userinfo.idcardnumb+"</label>";
	$(idcardnumb).appendTo("#idcardnumb");
	var payment = " <label class='well-sm lifont' >"+userinfo.payment+"</label>";
	$(payment).appendTo("#payment");
	var subscribeway = " <label class='well-sm lifont' >"+userinfo.subscribeway+"</label>";
	$(subscribeway).appendTo("#subscribeway");
	var usercode = " <label class='well-sm lifont' >"+userinfo.usercode+"</label>";
	$(usercode).appendTo("#usercode");
	var roleDetail = " <label class='well-sm lifont' >"+userinfo.roleDetail+"</label>";
	$(roleDetail).appendTo("#roleDetail");
	var rigisterdate = " <label class='well-sm lifont' >"+userinfo.rigisterdate.replace(/_/g," / ")+"</label>";
	$(rigisterdate).appendTo("#rigisterdate");
	
}
//获取用户操作日志
function getOperationLog(url,user_id){
	$.ajax({
		"type":"get",
		"url":'../LogInfoServlet?method=GetUserLogInfoList',
		"data":{
			"user_id":user_id,
			"pagenum":1
		},
		success:function(data){
			console.log("operationlog="+data);
			var recordsTotal = JSON.parse(data).recordsTotal;
			var loginfo = JSON.parse(data).LogInfo;
			addUserLogInfo(recordsTotal,loginfo);
		
		},
		error:function(){
			console.log("error");
		}
	})
}
function addUserLogInfo(recordsTotal,loginfo){
	$.each(loginfo,function(index,value){
		var tr=$("<tr><td>"+this.username+"</td><td>"+this.operationdate+"</td><td>"+this.operation+"</td><td>"+this.ipadd+"</td></tr>");
		$("#operatinoLogTable").append(tr);
	})
	 var url ='../LogInfoServlet?method=GetUserLogInfoList';
    pageMaker(recordsTotal,url,"logPagetoolBar");
}
//获取用户缴费情况
function getPaymentsInfo(url,user_id){
	$.ajax({
		"type":"get",
		"url":'../ChargeInfoServlet?method=GetChargeInfo',
		"data":{
			"user_id":user_id,
			"pagenum":1
		},
		success:function(data){
			console.log("payment="+data);
			var recordsTotal = JSON.parse(data).recordsTotal;
			var chargeInfo = JSON.parse(data).ChargeInfo;
			addUserPaymentInfo(recordsTotal,chargeInfo);
		
		},
		error:function(){
			console.log("error");
		}
	})
}
function addUserPaymentInfo(recordsTotal,chargeInfo){
	$.each(chargeInfo,function(index,value){
		var tr=$("<tr><td>"+this.username+"</td><td>"+this.payment+"</td><td>"+this.paydate+"</td><td>"+this.startdate+
				"</td><td>"+this.enddate+"</td><td>"+this.item+"</td><td>"+this.operator+"</td></tr>");
		$("#chargeInfoTable").append(tr);
	})
	var url ='../ChargeInfoServlet?method=GetChargeInfo';
    pageMaker(recordsTotal,url,"paymentPagetoolBar");
}
//获取用户关注的网页信息
function getUserWebsite(url,user_id){
	$.ajax({
		"type":"get",
		"url":url,
		"data":{
			"user_id":user_id,
		},
		success:function(data){
			console.log("UserWebsite="+data);
			var recordsTotal = JSON.parse(data).recordsTotal;
		    var websites = JSON.parse(data).websites;
		    $.each(websites,function(indexs,values){
		    	var tr = "<tr><td>"+this.website+"</td><td>"
    			+this.date+"</td>";
		    	var btn = "<td class='center'>"
		             +"<button id='"+this._id+"_delete' class='btn btn-danger' >"
		                 +"<i class='glyphicon glyphicon-trash icon-white'></i>删除</button></td></tr>";
//				    	遍历添加行
			    	var tr = tr + btn;
			    	$("#userWebsiteTable").append(tr);
//			    	绑定删除按钮点击事件
			    	var btndelete_id =this._id+"_delete";
			    	$("#"+btndelete_id).click(function(){
				    		var website_id = this.id.split("_");
				    		deleteWebsite(website_id[0]);
			    	});   
		    });
		},
		error:function(){
			console.log("error");
		}
	});
}
//删除用户关注的网页
function deleteWebsite(website_id){
	$.ajax({
		"type":"post",
		"url":"../UserWebsiteServlet?method=removeWebsites",
		"data":{
			"website_id":website_id,
		},
		success:function(data){
//			移除原有的表格  重新生成
			$("tbody").remove();
			console.log(data);
			location.reload();
//			location.replace("../WebManagement/user.jsp#webpage");
		},
		error:function(){
			console.log("error");
		}
	});
}
//获取用户关注的关键词
function getUserKeyword(url,user_id){
	$.ajax({
		"type":"get",
		"url":url,
		"data":{
			"user_id":user_id,
		},
		success:function(data){
			console.log("UserKeyword="+data);
			var recordsTotal = JSON.parse(data).recordsTotal;
		    var keywords = JSON.parse(data).keywords;
		    $.each(keywords,function(indexs,values){
		    	var tr = "<tr><td>"+this.keyword+"</td><td>"
    			+this.date+"</td>";
		    	var btn = "<td class='center'>"
		             +"<button id='"+this._id+"_delete' class='btn btn-danger' >"
		                 +"<i class='glyphicon glyphicon-trash icon-white'></i>删除</button></td></tr>";
//				    	遍历添加行
			    	var tr = tr + btn;
			    	$("#userKeywordTable").append(tr);
//			    	绑定删除按钮点击事件
			    	var btndelete_id =this._id+"_delete";
			    	$("#"+btndelete_id).click(function(){
				    		var website_id = this.id.split("_");
				    		deleteKeyword(website_id[0]);
			    	});  
		    }); 
		},
		error:function(){
			console.log("error");
		}
	});
}
//删除用户关注的关键词
function deleteKeyword(keyword_id){
	$.ajax({
		"type":"post",
		"url":"../UserKeywordServlet?method=removeKeyword",
		"data":{
			"keyword_id":keyword_id,
		},
		success:function(data){
//			移除原有的表格  重新生成
			$("tbody").remove();
			console.log(data);
			location.reload();
//			location.replace("../WebManagement/user.jsp#webpage");
		},
		error:function(){
			console.log("error");
		}
	});
}